package com.xiaotu.mapper;

import com.xiaotu.model.VerifyCodeInfoModel;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

/**
 * @author zhangxiao
 * @create 2022-03-08 16:17
 */
@org.apache.ibatis.annotations.Mapper
public interface VerifyCodeInfoMapper extends Mapper<VerifyCodeInfoModel> {

    /**
     * 根据手机号查询有效的验证码
     *
     * @param phone 手机号
     * @param type  验证码类型
     * @return
     * @throws Exception
     */
    @Select("select * from tab_verify_code_info where phone = #{phone}  and valid = '1' and type = #{type} ")
    VerifyCodeInfoModel queryVaildCodeByPhoneAndType(@Param("phone") String phone, @Param("type") String type);

    /**
     * 修改验证码无效
     *
     * @param invalid
     * @param id
     */
    @Update("<script>"
            + "update tab_verify_code_info "
            + " set valid = #{invalid} where id = #{id} "
            + "</script>")
    void updateValidCodeInvalid(@Param("invalid") String invalid, @Param("id") Integer id);

    /**
     * 修改验证码无效
     *
     * @param invalid
     */
    @Update("<script>"
            + "update tab_verify_code_info "
            + " set valid = #{invalid} where phone = #{phone} AND valid = '1' "
            + "</script>")
    void updValidCodeInvalidByPhone(@Param("invalid") String invalid, @Param("phone") String phone);

}
